<template>
      <div class="app-container baseProcess">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="流程名称" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入流程名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini">重置</el-button>
          </el-form-item>
        </el-form>

        <div ref="topButton">
            <el-row :gutter="10" class="mb8">
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
        </div>
        <div id="scrollTable">
            <el-table :height="tableHeight" v-loading="loading" v-adaptive="{bottomOffset: 85}" :data="dataList">
              <el-table-column label="流程名称" align="center" prop="processName" />
              <el-table-column label="流程编号" align="center" prop="orderNo" />
              <el-table-column label="流程启动时间" align="center" prop="orderCreateTime" />
              <el-table-column label="任务名称" align="center" prop="taskName" />
              <el-table-column label="任务创建时间" align="center" prop="taskCreateTime" />
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="lookProcess(scope.row)"
                  >查看流程图</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleProcess(scope.row)"
                  >处理</el-button>
                </template>
              </el-table-column>
            </el-table>
        </div>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 添加或修改Snaker流程对话框 -->
        <el-dialog :title="title" v-if="open" :visible.sync="open" width="80%" append-to-body v-dialogDrag>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <div class="logic-flow-view">
              <SnakerFlowDesigner :viewer="true" ref='designer' v-model="flowData" :high-light="highLight"/>
            </div>
          </el-form>
        </el-dialog>

        <el-dialog :title="handleTitle" v-if="handleOpen" :visible.sync="handleOpen" width="40%" append-to-body v-dialogDrag>
          <!-- 业务数据 -->
          <div>业务主表数据，当前环境未添加业务主表，需用户根据自身业务补充</div>
          <!-- 当前节点处理表单 -->
          <div>业务处理表单可参考流程发起时的操作，动态加载流程表单</div>
        </el-dialog>
      </div>
</template>

<script>
import { getUserTasks,getProcessDsiplay } from "@/api/base/baseProcess";

export default {
  name: "usertasks",
  data() {
    return {
      tableHeight:500,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户任务
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo:1,
        pageSize:15
      },
      // 表单参数
      form: {},
      // 流程定义数据
      flowData:"",
      // 高亮数据
      highLight:{
        historyNodeNames:[],
        historyEdgeNames:[],
        activeNodeNames:[],
      },
      handleTitle:"",
      handleOpen:false,
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询Snaker流程列表 */
    getList() {
      this.loading = true;
      getUserTasks(this.queryParams).then(response => {
        this.dataList = response.data.result;
        this.total = response.data.totalCount;
        this.loading = false;
      });
    },
    lookProcess(row){
      let parm = {
        processId:row.processId,
        orderId:row.orderId
      };
      console.log(parm);
      getProcessDsiplay(parm).then(res=>{
        let data = res.data;
        console.log(data);
        this.flowData = data.processInfo;
        this.highLight.historyNodeNames = data.historyNodeNames;
        this.highLight.activeNodeNames = data.activeNodeNames;
        this.open = true;
      })
    },
    handleProcess(row){
      this.handleTitle = row.taskName;
      this.handleOpen = true;
    }
  }
};
</script>
<style scoped>
.logic-flow-view {
  height: 75vh;
  position: relative;
}
</style>
